package br.org.credfaz.sis.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import br.org.credfaz.sis.MysqlConnectionFactory;
import br.org.credfaz.sis.modelo.EmailCliente;

public class EmailClienteDAO {
	
private final Connection connection;
	
	public EmailClienteDAO(){
		try{
			connection = new MysqlConnectionFactory().getConnection();
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}
	
	public void adiciona(EmailCliente emailcliente){
		String sql = "insert into emailcliente (idemailcliente, idcliente, codtipoemail, descemail) values (?, ?, ?, ?)";
		PreparedStatement stmt;
		try{
			stmt = connection.prepareStatement(sql);
			
			stmt.setInt(1, emailcliente.getIdemailcliente());
			stmt.setLong(2, emailcliente.getIdcliente());
			stmt.setInt(3, emailcliente.getCodtipoemail());
			stmt.setString(4, emailcliente.getDescemail());
					
			
			stmt.execute();
			
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}

}
